package com.wt.ai.demo.service.impl;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor;
import org.springframework.stereotype.Service;

import com.wt.ai.demo.domain.dto.ChatDTO;
import com.wt.ai.demo.service.WtAIChatService;

import jakarta.annotation.Resource;
import reactor.core.publisher.Flux;

@Service
public class WtAIChatServiceImpl implements WtAIChatService {
    @Resource
    private ChatClient dashScopeChatClient;

    @Override
    public Flux<String> streamChat(ChatDTO chatDTO) {
        return dashScopeChatClient.prompt()
                .user(chatDTO.getQuery())
                .advisors(advisor -> advisor.param(AbstractChatMemoryAdvisor.CHAT_MEMORY_CONVERSATION_ID_KEY,
                        chatDTO.getId()))
                .stream()
                .content()
                .concatWith(Flux.just("[DONE]"));
    }

}
